import 'package:base_flutter/base_flutter.dart';

import '../model/user_model.dart';
import '../net/response/user_data.dart';

class AccountManager{

  static AccountManager? _instance;

  static AccountManager get instance => _instance??= AccountManager._();

  bool get hasCircle => !(userData?.circleIds??"").isNullOrEmpty();

  var userModel = UserModel();

  UserData? userData;

  AccountManager._(){
    SpUtil.getInstance();
  }


  var token = "";

  Future<void> init()  async {
    token =  SpUtil.getString("token")??"";
    if(!token.isNullOrEmpty()){
      ///获取用户信息
      await getUserInfo();
    }


  }

  Future<void> saveToken(String token) async {
    this.token = token;
    SpUtil.putString("token", token);
    await getUserInfo();
  }

  Future<void> getUserInfo() async{
    try{
      userData =  await userModel.userInfo();
    }catch(e){
      print(e);
    }
  }



}